from django.db import models
import time


# 车间表
class FaKuyouWorkshop(models.Model):
    STATUS_CHOICES = [
        ('0', '关闭'),
        ('1', '正常')
    ]

    id = models.AutoField(primary_key=True, verbose_name='ID')
    code = models.CharField(
        max_length=30,
        default='',
        verbose_name='车间编号',
        help_text='车间的唯一编号标识'
    )
    name = models.CharField(
        max_length=255,
        default='',
        verbose_name='车间名称',
        help_text='车间的显示名称'
    )
    status = models.CharField(
        max_length=1,
        choices=STATUS_CHOICES,
        default='1',
        verbose_name='状态',
        help_text='控制车间是否可用'
    )
    createtime = models.IntegerField(
        null=True,
        blank=True,
        verbose_name='创建时间',
        help_text='记录创建的时间戳',
        default=time.time()
    )
    updatetime = models.IntegerField(
        null=True,
        blank=True,
        verbose_name='更新时间',
        help_text='最后更新的时间戳',
        default=time.time()
    )

    class Meta:
        db_table = 'fa_kuyou_workshop'
        verbose_name = '车间'
        verbose_name_plural = '车间管理'
        indexes = [
            models.Index(fields=['code']),  # 车间编号作为常用查询条件
            models.Index(fields=['status']),  # 按状态筛选
        ]
        ordering = ['code']  # 默认按编号排序

    def __str__(self):
        return f"{self.code} - {self.name}"
